﻿using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;


namespace SelfService.ViewModel.SysScreenQueueVMs
{
    public partial class SysScreenQueueListVm : BasePagedListVM<SysScreenQueueView, SysScreenQueueSearcher>
    {

        protected override IEnumerable<IGridColumn<SysScreenQueueView>> InitGridHeader()
        {
            return new List<GridColumn<SysScreenQueueView>>{
                this.MakeGridHeader(x => x.DepartmentName),
                this.MakeGridHeader(x => x.DoctorName),
                this.MakeGridHeader(x => x.Info),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeader(x => x.RoomName),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysScreenQueueView> GetSearchQuery()
        {
            var query = DC.Set<SysScreenQueue>()
                .CheckEqual(Searcher.RoomId, x=>x.RoomId)
                .CheckEqual(Searcher.DoctorId, x=>x.DoctorId)
                .CheckContain(Searcher.Info, x=>x.Info)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .Select(x => new SysScreenQueueView
                {
				    ID = x.ID,
                    DepartmentName = x.Room.DepartmentName,
                    DoctorName = x.Doctor.Name,
                    RoomName = x.Room.Name,
                    Info = x.Info,
                    CreateTime = x.CreateTime,
                })
                .OrderByDescending(x => x.CreateTime);
            return query;
        }

    }

    public class SysScreenQueueView : SysScreenQueue{

        [Display(Name = "科室名称")]
        public string DepartmentName { get; set; }

        [Display(Name = "诊室名称")]
        public string RoomName { get; set; }

        [Display(Name = "医生名称")]
        public string DoctorName { get; set; }

    }
}
